//
//  JHToolsDefine.swift
//  JHToolsModule_Swift
//
//  Created by iOS on 15/11/2019.
//  Copyright © 2019 HU. All rights reserved.
//

import UIKit
import Foundation

// MARK: ===================================工具类:变量宏定义=========================================

// MARK:- 屏幕
/// 当前屏幕状态 宽度
public let ScreenHeight = max(UIScreen.main.bounds.width, UIScreen.main.bounds.height)
/// 当前屏幕状态 高度
public let ScreenWidth = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height)

/// 当前屏幕状态 宽度按照4.7寸 375 屏幕比例 例如 30*FitWidth即可
public let FitWidth = ScreenWidth / 375
/// 当前屏幕状态 高度按照4.7寸 667 屏幕比例 例如 30*FitHeight即可
public let FitHeight = ScreenHeight / 667
/// 当前屏幕比例
public let Scare = UIScreen.main.scale
/// 画线宽度 不同分辨率都是一像素
public let LineHeight = CGFloat(Scare >= 1 ? 1/Scare: 1)

/// 信号栏高度
/// - Returns: 高度
public func StatusBarHeight() ->CGFloat {
    if #available(iOS 13.0, *){
        let window = UIApplication.shared.windows.first
        return window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
    }else{
        return UIApplication.shared.statusBarFrame.height
    }
}

/// 导航栏高度 实时获取,可获取不同分辨率手机横竖屏切换后的实时高度变化
/// - Returns: 高度
public func NavBarHeight() ->CGFloat {
    return UINavigationController().navigationBar.frame.size.height
}

/// 获取屏幕导航栏+信号栏总高度
public let NavAndStatusHeight = StatusBarHeight() + NavBarHeight()
/// 获取刘海屏底部home键高度,普通屏为0
public let BottomHomeHeight = UIApplication.shared.windows[0].safeAreaInsets.bottom

/// TabBar高度 实时获取,可获取不同分辨率手机横竖屏切换后的实时高度变化
/// - Returns: 高度
public func TabbarHeight() ->CGFloat {
    return UITabBarController().tabBar.frame.size.height
}
//刘海屏=TabBar高度+Home键高度, 普通屏幕为TabBar高度
public let TabBarHeight = TabbarHeight() + BottomHomeHeight

public func getNavHeight() -> CGFloat {
    var height:CGFloat = 0
    if IsBangs_iPhone() {
        height = 84
    }else{
        height = 64
    }
    return height
}

/// 判断是否iphoneX 带刘海
public func IsBangs_iPhone() -> Bool {
    guard #available(iOS 11.0, *) else {
        return false
    }
    let isX = UIApplication.shared.windows[0].safeAreaInsets.bottom > 0
    return isX
}

public var isX: Bool {
        var isX = false
        if #available(iOS 11.0, *) {
            let bottom: CGFloat = UIApplication.shared.delegate?.window??.safeAreaInsets.bottom ?? 0
            isX = bottom > 0.0
        }
        return isX
    }

///判断是否iPad
public let IsIPAD: Bool = (UIDevice.current.userInterfaceIdiom == .pad) ? true: false


// MARK:- 系统版本
public let SystemVersion: String = UIDevice.current.systemVersion

public func Later_iOS11() -> Bool {
    guard #available(iOS 11.0, *) else {
        return false
    }
    return true
}

public func Later_iOS12() -> Bool {
    guard #available(iOS 12.0, *) else {
        return false
    }
    return true
}

public func Later_iOS13() -> Bool {
    guard #available(iOS 13.0, *) else {
        return false
    }
    return true
}

public func Later_iOS14() -> Bool {
    guard #available(iOS 14.0, *) else {
        return false
    }
    return true
}

public func Later_iOS15() -> Bool {
    guard #available(iOS 15.0, *) else {
        return false
    }
    return true
}

// MARK:- App信息

/// App 显示名称
public var AppDisplayName: String? {
    return Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String
}

public var AppName: String? {
    return Bundle.main.infoDictionary?[kCFBundleNameKey as String] as? String
}

/// app 的bundleid
public var AppBundleID: String? {
    return Bundle.main.bundleIdentifier
}

/// build号
public var AppBuildNumber: String? {
    return Bundle.main.object(forInfoDictionaryKey: kCFBundleVersionKey as String) as? String
}

/// app版本号
public var AppVersion: String? {
    return Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String
}

// MARK:- 字体
/// 系统默认字体
public let Font9 = UIFont.systemFont(ofSize: 9)
public let Font10 = UIFont.systemFont(ofSize: 10)
public let Font11 = UIFont.systemFont(ofSize: 11)
public let Font12 = UIFont.systemFont(ofSize: 12)
public let Font13 = UIFont.systemFont(ofSize: 13)
public let Font14 = UIFont.systemFont(ofSize: 14)
public let Font15 = UIFont.systemFont(ofSize: 15)
public let Font16 = UIFont.systemFont(ofSize: 16)
public let Font18 = UIFont.systemFont(ofSize: 18)


// MARK: - 常用快捷方式
public let kUserDefaults = UserDefaults.standard

public let kNotifiDefault = NotificationCenter.default

// token
public var kUserToken: String {
    return kUserDefaults.value(forKey: kUserTokenKey) as? String ?? ""
}
//token
public var kUserPhone: String {
    return kUserDefaults.value(forKey: kUserPhoneKey) as? String ?? ""
}


func removeAllData() {
    let defaults = UserDefaults.standard
    let dictionary = defaults.dictionaryRepresentation()
    dictionary.keys.forEach { key in
        defaults.removeObject(forKey: key)
    }
}


// 是否登录
public var kIsLogin: Bool {
    return !kUserToken.isEmpty
}

/// 未来宝贝scheme  wlbb.net 生产futurebaobei.com
//public var kWLBBScheme: String {
//
//    return FXEnvironment.shared.isRelase ? "futurebaobei.com" : "wlbb.net"
//}
public var kFxhealthScheme: String {
    return "billfosunuhipaycenterapp"
}
